/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: 86187
 * Date: 2022-07-19
 * Time: 19:17
 */

public class ArrayList {
    public static void main(String[] args) {

        MyArrayList myArrayList = new MyArrayList();

        myArrayList.add(1);//尾插
        myArrayList.add(8);
        myArrayList.add(65);
        myArrayList.add(45);
        myArrayList.add(57);
        myArrayList.add(3,97);//pos位置插入数据

        myArrayList.display();//打印

        //查找数据，该元素不存在就返回-1
        System.out.println(myArrayList.contains(6));

        // 获取某元素的下标，该元素不存在就返回-1
        int tmp = myArrayList.indexOf(5);
        if(tmp != -1) {
            System.out.print("您要获取的下标是: ");
            System.out.println(tmp);
        }

        //获取pos 位置的数据，pos 不合法返回-1
        int ret = myArrayList.getVal(4);
        if(ret != -1) {
            System.out.print("您要获取的数据是: ");
            System.out.println(ret);
        }

        myArrayList.setVal(3,520);
        myArrayList.display();//打印

        myArrayList.add(1314);
        myArrayList.display();//打印

        myArrayList.deletePos(0);//删除第一个元素
        myArrayList.display();//打印

        myArrayList.deletePos(5);//删除5号下标的数据
        myArrayList.display();//打印


        // //获取顺序表长度
        System.out.print("顺序表长度为:");
        System.out.println(myArrayList.getSize());
        System.out.println();

        myArrayList.removeKey(3);
        myArrayList.display();//打印

        // 获取顺序表长度
        System.out.print("顺序表长度为:");
        System.out.println(myArrayList.getSize());
        System.out.println();

        //清空顺序表
        myArrayList.clear();

        // 获取顺序表长度
        System.out.print("顺序表长度为:");
        System.out.println(myArrayList.getSize());
    }

}
